--霆鸣云裂
local tingmingyunlie = fk.CreateSkill {
    name = "mcdh_tingmingyunlie",
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

tingmingyunlie:addEffect('active',{
    prompt = "#mcdh_tingmingyunlie-active",
    card_num = 1,
    target_num = 1,
    can_use = function(self, player)
        return player:usedSkillTimes(self.name, Player.HistoryPhase) < 1
    end,
    card_filter = function(self,player, to_select, selected, targets)
        return #selected == 0
    end,
    target_filter = function(self, player,to_select, selected)
        return #selected == 0 and to_select ~= player
    end,
    on_use = function(self, room, effect)
        local player = effect.from
        local target =effect.tos[1]
        local bool = false
        local extinfo = "、或判定：为♠时受到2点雷电伤害"
        room:moveCards({
            ids = effect.cards,
            from = player,
            fromArea = Player.Hand,
            toArea = Card.DrawPile,
            moveReason = fk.ReasonPut,
            skillName = self.name
        })
        repeat
            local cids = room:askForCard(
                    target,
                    1, 1,
                    true,
                    self.name,
                    not bool,
                    ".",
                    "#mcdh_tingmingyunlie-choice" .. player.id .. "::" .. extinfo
            )
            if #cids > 0 then
                room:obtainCard(
                        player,
                        cids,
                        true,
                        fk.ReasonGive,
                        target.id,
                        self.name
                )
                extinfo = ""
                bool = #player:getCardIds("h") < #target:getCardIds("h")
            else
                local judge = {
                    who = target,
                    reason = self.name,
                    pattern = ".|.|spade",
                }
                room:judge(judge)
                if judge.card.suit == Card.Spade  then
                    room:damage {
                        to = target,
                        from = player,
                        damage = 2,
                        damageType = fk.ThunderDamage,
                        skillName = self.name
                    }
                end
            end
        until not bool
    end,
})

Fk:loadTranslationTable {
    ["mcdh_tingmingyunlie"] = "霆鸣云裂",
    [":mcdh_tingmingyunlie"] = "出牌阶段限一次，你可以将一张手牌置于牌堆顶，令一名其他角色选择一项：1.判定，若结果为♠，你对其造成2点雷电伤害；2.交给你一张牌，然后若其手牌数大于你，则重复该选项。",
    ["#mcdh_tingmingyunlie-active"] = "霆鸣云裂：将一张手牌置于牌堆顶并选择一名其他角色",
    ["#mcdh_tingmingyunlie-choice"] = "霆鸣云裂：交给 %src 一张牌%arg",
}

return tingmingyunlie